The fantasia (from Italian: fantasia; also English: fantasy, fancy, phantasy, German: Fantasie, Phantasie, French: fantaisie) is a musical composition with its roots in the art of improvisation. Because of this, it seldom approximates the textbook rules of any strict musical form (as with the impromptu).
The term was first applied to music during the 16th century, at first to refer to the imaginative musical "idea" rather than to a particular compositional genre. Its earliest use as a title was in German keyboard manuscripts from before 1520, and by 1536 is found in printed tablatures from Spain, Italy, Germany, and France. From the outset, the fantasia had the sense of "the play of imaginative invention", particularly in lute or vihuela composers such as Francesco Canova da Milano and Luis de Milánn. Its form and style consequently ranges from the freely improvisatory to the strictly contrapuntal, and also encompasses more or less standard sectional forms (Field 2001).
In the Baroque and Classical music eras, a fantasia was typically a piece for keyboard instruments with alternating sections of rapid passagework and slower, more melodic passages. From the Baroque period, J. S. Bach's Chromatic Fantasia and Fugue, BWV 903, for harpsichord; Great Fantasia and Fugue in G minor, BWV 542, for organ; and Fantasia and Fugue in C minor, BWV 537, for organ are examples. For an example from the Classical period, see Mozart's Fantasia in D minor, K. 397 for fortepiano, along with his Fantasia in C minor, K. 475. In contemporary music, Busoni's Fantasia contrappuntistica or Corigliano's Fantasia on an ostinato are examples of a fantasia.
The term also referred in the Baroque era (more specifically British Tudor music) to pieces for viols, characteristically- though not always- alternating, in this case rapid fugal sections with slower sections in slow notes and sometimes clashing harmonies. According to the Oxford Concise Dictionary of Music's entry the instrumental fantasia was closely related in its history and form to the motet. Henry Purcell's fantasias are the last Baroque representatives of the breed, although Walter Willson Cobbett, in the opening decades of the 20th century, attempted to resurrect something of this style via a competition, to which works like John Ireland's and Frank Bridge's Phantasie Trios, Benjamin Britten's Phantasie Quartet (for oboe and strings) and other music owe their existence.
In the Romantic period, two contradictory trends greatly affected the fantasia: one was the decline of formal improvisation as a test of the compositional technique; the other was the move by composers toward freer forms. Chopin's Fantaisie in F minor, Op. 49, combines various keyboard textures of the stile brillante with the classical sonata paradigm, resulting in a work of unorthodox but sophisticated form. Schumann's Fantasie in C, Op. 17, is a cornerstone of the Romantic piano repertoire. His numerous 'fantasy pieces' are character works on a smaller scale, often bearing descriptive titles.